<template>
	<view class="home">
		<swiper class="swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval" :duration="duration"
		 :circular="circular">
			<swiper-item v-for="item in swipers" :key="item.id" @click="goWorkDetail(item.id)">
				<image :src="'data:image/jpeg;base64,' + item.img"></image>
			</swiper-item>
		</swiper>
		<!-- 导航区域 -->
		<view class="nav">
			<view class="nav_item" v-for="(item,index) in navs" :key="index" @click="navItemClick(item.path)">
				<view :class="item.icon"></view>
				<text>{{item.title}}</text>
			</view>
		</view>
		<!-- 推荐作品区 -->
		<view class="hot_works">
			<view class="tit">推荐作品</view>
			<work-list :works="works" @workItemClick="goWorkDetail"></work-list>
		</view>
	</view>
</template>

<script>
	import workList from '../../components/work-list/work-list.vue'
	export default {
		data() {
			return {
				swipers: [],
				works:[],
				navs:[
					{
						icon:"iconfont icon-works",
						title:"产品集市",
						path:"/pages/works/works"
					},{
						icon:"iconfont icon-concatus",
						title:"联系我们",
						path:"/pages/concat/concat"
					},{
						icon:"iconfont icon-community",
						title:"猿区生活",
						path:"/pages/community/community"
					},{
						icon:"iconfont icon-ziliao",
						title:"资料内容",
						path:"/pages/ziliao/ziliao"
					}
				],
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				circular: true
			}
		},
		onLoad() {
			console.log("onLoad");
			this.getSwipers();
			this.getHotWorks();
		},
		components:{
			"work-list":workList
		},
		methods: {
			
			navItemClick(url){
				uni.navigateTo({
					url
				})
			},
			//跳转作品详情页
			goWorkDetail(id){
				uni.navigateTo({
					url:"/pages/work-detail/work-detail?id="+id
				})
			},
			async getSwipers() {
				console.log("getSwipers");
				const res = await this.$myRequest({
					url: "/works/swiperImgList"
				})
				console.log( res);
				this.swipers = res.data.data;
				// uni.request({
				// 	url:"http://localhost:8080/users/swiperImgList",
				// 	success: (res) => {
				// 		console.log(res)
				// 		if(res.statusCode == '200'){
				// 			this.swipers = res.data;
				// 		}else{
				// 			return uni.showToast({
				// 			    title: '获取数据失败',
				// 			    duration: 2000
				// 			});
				// 		}
				// 	}
				// })
			},
			//获得热门作品
			async getHotWorks(){
				const res = await this.$myRequest({
					url: "/works/getHotWorksList?pageindex=1"
				})
				console.log(res);
				this.works = res.data.data;
			}
		}
	}
</script>

<style lang="scss">
	.home{
		swiper{
			width: 100%;
			height: 390rpx;
			image{
				height: 100%;
				width: 100%;
			}
		}
		.nav{
			display: flex;
			margin-top: 20rpx;
			.nav_item{
				width: 25%;
				text-align: center;
				view{
					width: 120rpx;
					height: 120rpx;
					border-radius: 60rpx;
					background: $shop-color;
					margin: 10rpx auto;
					line-height: 120rpx;
					color:#FFFFFF;
					font-size: 55rpx;
				}
				text{
					font-size: 30rpx;
				}
			}
		}
		.hot_works{
			background: #eee;
			overflow: hidden;
			margin-top: 20rpx;
			.tit{
				height: 100rpx;
				line-height: 100rpx;
				color:$shop-color;
				text-align: center;
				letter-spacing: 40rpx;
				background: #ffffff;
				margin: 7rpx 0;
			}
		}
		
	}
</style>
